package com.itheima.config;

import com.itheima.interceptor.Myinterceptor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MvcConfig implements WebMvcConfigurer {

    /**
     * 将拦截器注册到ioc容器中
     * @return
     */
    @Bean
    public Myinterceptor myinterceptor(){
        return new Myinterceptor();
    }

    /**
       * 重写该方法；往拦截器链添加自定义拦截器
       * @param registry 拦截器链
       */

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(myinterceptor()).addPathPatterns("/**");
    }
}
